package com.mbuswidget;

import java.util.ArrayList;

import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MBusWidgetConfigurationStopsRemoveStop extends Activity {
	private int widgetID = AppWidgetManager.INVALID_APPWIDGET_ID;
	private ListView itemList;
	private ArrayList<String> listofstops;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.selectstopby);
		setResult(RESULT_CANCELED);

		TextView topLabel = (TextView) findViewById(R.id.Toplbl);
		topLabel.setText(R.string.chooseStopSelectionMethodTxt);

		widgetID = getIntent().getExtras().getInt(
				AppWidgetManager.EXTRA_APPWIDGET_ID,
				AppWidgetManager.INVALID_APPWIDGET_ID);

		SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(this);
		listofstops = MBusWidgetConstants.GetWidgetStopList(prefs, widgetID);
		itemList = (ListView) findViewById(R.id.itemList);
		itemList.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, listofstops));
		itemList.setOnItemClickListener(new OnItemClickListener() {
			// @Override
			public void onItemClick(AdapterView<?> a, View v, int position,
					long id) {
				
				int[] selectedStops = new int[1];
				selectedStops[0] = (int)id;
				
				// This is show all stops
				Intent intent = getIntent();
				intent.putExtra(MBusWidgetConstants.STOP_TYPE, MBusWidgetConstants.REMOVE_STOP);
				intent.putExtra(MBusWidgetConstants.INTENT_SELECTED_STOPS, selectedStops);
				intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetID);
				setResult(RESULT_OK, intent);
				finish();
			}
		});
	}
}
